<html>
<head>
    <meta charset="utf-8">
    <meta name="author" content="Ajj">
    <title>轮播图</title>
    <script src="jquery-3.1.1.js"></script>
    <style>
        ul,
        li {
            margin: 0;
            padding: 0;
            list-style-type: none;
            /*position: relative;*/
        }
        
        #box {
            width: 520px;
            height: 280px;
            margin: 100 auto;
            position: relative;
        }
        
        #box .list li {
            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }
        
        #box .list li.current {
            display: block;
        }
        
        #box .count {
            position: absolute;
            right: 10px;
            bottom: 0;
        }
        
        #box .count li {
            float: left;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: #fa0;
            text-align: center;
            line-height: 20px;
            margin-left: 10px;
            color: #fff;
            opacity: 0.8;
            cursor: pointer;
        }
        
        #box .count li.current {
            background-color: orangered;
            opacity: 1;
        }
        #box .anniu{
            position: absolute;
            bottom: 0;
            left: 0;
        }
        #box .anniu li{
            float: left;
            background-color: #ccc;
            width: 20px;height: 30px;
            line-height: 30px;
            margin: 5px;
            margin-bottom: 0;
            text-align: center;
            font-size: 20px;
            opacity: 0.5;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div id="box">
        <ul class="list">
            <li class="current"><img src="img/1.jpg" alt=""></li>
            <li><img src="img/2.jpg" alt=""></li>
            <li><img src="img/3.jpg" alt=""></li>
            <li><img src="img/4.jpg" alt=""></li>
            <li><img src="img/5.jpg" alt=""></li>
        </ul>
        <ul class="count">
            <li class="current">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
        </ul>
        <ul class="anniu">
            <li class="qian"><</li>
            <li class="hou">></li>
        </ul>
    </div>
</body>
</html>
<script>
    var timer=null;
    var current=0;

    timer=setInterval(play,1000);
    // 自动
    function play(){
        current++;
        if(current==5){
            current=0;
        }
        show(current);
        console.log(current);
    };
    // 手动
    $('.count li').mouseover(function(){
        show($('.count li').index($(this)));
        console.dir($('.count li').index($(this)));
    });
    function show(index){
        current=index;
        $('.list li').each(function(){
            $(this).removeClass('current');
        });
        $('.count li').each(function(){
            $(this).removeClass('current');
        });
        $('.list li').eq(index).addClass('current');
        $('.count li').eq(index).addClass('current');
        console.log(index);
    }
    $('.anniu .qian').click(function(){
        current--;
        if(current<0){
            current=$('.list li').length-1;
        }
        show(current);
    });
    $('.anniu .hou').click(function(){
        current++;
        if(current>=$('.list li').length){
            current=0;
        }
        show(current);
    });
    $('#box').hover(function(){
        clearInterval(timer);
    },function(){
        timer=setInterval(play,1000);
    });
</script>